package sn.gandal.mobile.kalpet.server.account;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;

import android.util.Log;

public class AccountManagerSoap  {
	
	private static final String NAMESPACE = "http://guichet.kalpet.mobile.gandal.sn/";
	  private static final String URL = "http://192.168.0.30:8080/guichet_service/GuichetServiceService";
	  private static final String SOAP_ACTION_GET_ACCOUNT = "http://guichet.kalpet.mobile.gandal.sn/getAccount";
	  private static final String SOAP_ACTION_ADD_ACCOUNT = "http://guichet.kalpet.mobile.gandal.sn/addAccount";
	  private static final String SOAP_ACTION_AUTH_USER = "authUser";
	  
	  
	  private static final String METHOD_NAME_GET_ACCOUNT = "getAccount";
	  private static final String METHOD_NAME_ADD_ACCOUNT = "addAccount";
	  private static final String METHOD_NAME_AUTH_USER = "authUser";
	  
	  public String authUser(String numeroClient, String codeSecret) {
      String auth=null;
	   try {
	      SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME_AUTH_USER);
	      
	      request.addProperty("numeroClient", numeroClient);
	      request.addProperty("codeSecret", codeSecret);
	      
	      SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
	      envelope.setOutputSoapObject(request);
	      
	      
	      HttpTransportSE  androidHttpTransport = new HttpTransportSE (URL);
	      androidHttpTransport.call(SOAP_ACTION_AUTH_USER, envelope);
	    //  return  androidHttpTransport.requestDump.toString();
	      Log.d("DEBUG : getAuth : Resultat obtenu", "Ya-t-il exception ? ");
	      
	    //  SoapObject objetSOAP = (SoapObject)envelope.getResponse();
	    //  auth = this.parserObjet(objetSOAP, "authUserResponse ");

	    } catch (Exception e) {
	      Log.e("EXCEPTION SOAP : getAuth", "", e);
	      return "falseResponse";
	    }
	   // return "true";
	return auth;
	  }
	  
	  private String parserObjet(SoapObject objet, String property) {
		    SoapObject meteoObjet = (SoapObject)objet.getProperty(property);
		    String meteo = meteoObjet.getProperty("return").toString();
		    
		    return meteo;
		  } 


}
